package com.zhiyou100.action;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 数据 回显测试1
 *
 * @author yang
 * @version 1.0.0
 * @date 2020-09-06 17:25
 */

@Controller
@RequestMapping("/test01")
public class Test01 {
    @RequestMapping("/m1.action")
    public String testMethod1(Student s, Model m) {
        String firstName = "韩";
        if (s.getSname().startsWith(firstName)) {
            m.addAttribute("message", s.getSname() + " 登陆成功");
            return "success";
        }
        m.addAttribute("message", "账号或者密码错误！");
        return "index";
    }


    @RequestMapping("/m2.action")
    public String testMethod2(String sname, Integer sid, Double score, String sex, Model m) {
        String firstName = "韩";

        if (sname.startsWith(firstName)) {
            m.addAttribute("message", sname + " 登陆成功");
            return "success";
        }

        final Student student = Student.builder()
                .sname(sname)
                .sid(sid)
                .sex(sex)
                .score(score)
                .build();

        // 为了所有数据都回显，需要把所有数据都转给 request 中
        m.addAttribute("stu", student);

        m.addAttribute("message", "账号或者密码错误！");

        return "index";
    }

    @RequestMapping("/m3.action")
    public String testMethod3(TestMap testMap, Model m) {
        String firstName = "韩";
        String name = "sname";
        System.out.println(testMap);
        if (testMap.getMap().get(name).startsWith(firstName)) {
            m.addAttribute("message", testMap.getMap().get("sname") + " 登陆成功");
            return "success";
        }
        m.addAttribute("message", "账号或者密码错误！");

        return "index";
    }
}
